<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\feedback\model;

use app\cassification\model\ClassificationDictionary;
use plugin\saiadmin\basic\BaseModel;

/**
 * 反馈问题模型
 */
class feedback extends BaseModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'feedback_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_feedback';
    protected $append = ['feedback_classify_text'];
    
    /**
     * 用户名 搜索
     */
    public function searchUserNameAttr($query, $value)
    {
        $query->where('user_name', 'like', '%'.$value.'%');
    }
    public function searchUserIdAttr($query, $value)
    {
        $query->where('user_id', $value);
    }
    public function searchContactNumberAttr($query, $value)
    {
        $query->where('contact_number', 'like', '%'.$value.'%');
    }
    public function searchFeedbackClassifyAttr($query, $value)
    {
        $query->where('feedback_classify', $value);
    }
    public function searchCreateTimeAttr($query, $value)
    {   
        $query->whereBetweenTime('create_time', $value[0], $value[1]);
    }
    public function searchLangCodeAttr($query, $value){
        $query->where('lang_code', $value);
    }
    public function getFeedbackClassifyTextAttr($value,$data)
    {
        if(isset($data['feedback_classify'])){
            return    ClassificationDictionary::where('dictionary_id', $data['feedback_classify'])->value('classification_name_zh');
        }
        return '';
    }
    public function setFilesAttr($value){
        if(is_array($value)){
            return json_encode($value); 
        }
    }
    public function getFilesAttr($value){
        if($value){
            return json_decode($value,true); 
        } 
    }

}
